package cn.xuan.zp.web.article;

import cn.xuan.zp.service.article.IArticleService;
import cn.xuan.zp.service.article.IArticleTalkService;
import cn.xuan.zp.sys.Config;
import cn.xuan.zp.web.ov.ArticleVO;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

@Controller
@RequestMapping("/article")
public class ArticleController {
    private static final Logger LOGGER = LoggerFactory.getLogger(ArticleController.class);

    @Autowired
    private IArticleService articleService;
    @Autowired
    private IArticleTalkService articleTalkService;

    @ResponseBody
    @RequestMapping("/addArticle")
    public Object addArticle(/*java.util.Map<String,Object> params*/ArticleVO articleVO){
        /*if(params != null && !params.isEmpty()){
            for (Map.Entry<String, Object> param:params.entrySet()) {
                LOGGER.info(param.getKey()+"-"+param.getValue());
            }
        }*/
        LOGGER.info(articleVO.toString());
        try {
            articleService.addEnity(articleVO.getArticle());
        } catch (Exception e) {
            LOGGER.error("ArticleController.addArticle",e);
        }
        java.util.Map<String,Object> res = new HashMap<>();
        res.put(Config.REQUEST_PARAM_FLAG_RESULT,Config.REQUEST_PARAM_RESULT_SUCCESS);
        res.put(Config.REQUEST_PARAM_FLAG_MSG,"请求成功");
        return res;
    }

}
